package com.example.shop_2211.order

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.base.mvvm.BaseFragment
import com.example.shop_2211.R
import com.example.shop_2211.adapter.OrderInfoAdapter
import com.example.shop_2211.databinding.FragmentPayedBinding
import com.example.shop_2211.databinding.FragmentPayingBinding

class PayedFragment  : BaseFragment<FragmentPayedBinding, OrderViewModel>() {
    lateinit var orderInfoAdapter: OrderInfoAdapter
    override fun initView() {
        orderInfoAdapter = OrderInfoAdapter()
        binding.rv.adapter = orderInfoAdapter
        binding.rv.layoutManager = LinearLayoutManager(context)
        viewModel.order("1",10,1)

    }

    override fun initData() {
        viewModel.orderSuccess.observe(this){
            if(it.code==200){
                orderInfoAdapter.data.clear()
                it.data.list.forEach {
                    orderInfoAdapter.data.addAll(it.orderInfoList)
                }
                orderInfoAdapter.notifyDataSetChanged()
            }
        }
    }

    override fun getViewModel(): Class<OrderViewModel>   = OrderViewModel::class.java

    override fun getLayout(): Int = R.layout.fragment_payed

}